package com.smooth.site.sx.pc.jifen.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smooth.common.pc.interceptor.PcAccountContext;
import com.smooth.common.site.common.enums.SiteCodeEnums;
import com.smooth.common.site.common.excep.SiteException;
import com.smooth.common.site.common.rsp.ReturnResult;
import com.smooth.dao.gen.bean.BizOrder;
import com.smooth.dao.gen.bean.BizStudent;
import com.smooth.site.sx.pc.jifen.service.PcOrderService;
import com.smooth.site.sx.pc.jifen.vo.SubOrderReq;
import com.smooth.sys.pc.vo.ListRsp;
import com.smooth.sys.site.biz.pay.enums.OrderStatus;

@Controller
@RequestMapping(value = "/pc")
public class PcOrderController {
	@Autowired
	PcOrderService pcOrderService;
	/**
	 * 学生注册
	 * @param studenRegVo
	 * @param result
	 * @param request
	 * @param response
	 * @return
	 */
	
	@RequestMapping(value = {"c/order/submit"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult submit(@Valid  SubOrderReq subOrderReq, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizStudent bizStudent = (BizStudent)PcAccountContext.getObj(BizStudent.class);
		BizOrder bizOrder = pcOrderService.submitOrder(subOrderReq,bizStudent);
		returnResult.setData(bizOrder);
		return returnResult;
	}
	
	@RequestMapping(value = {"c/order/list"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult list(Integer orderStatus,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		String telNo = PcAccountContext.getTelNo();
		ListRsp<BizOrder> brsp = pcOrderService.queryOrderList(telNo, OrderStatus.getStatus(orderStatus));
		returnResult.setData(brsp);
		return returnResult;
	}
	
	
	@RequestMapping(value = {"c/order/detail"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult detail(String orderNo,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizOrder bizOrder = pcOrderService.queryDetail(orderNo);
		String telNo = PcAccountContext.getTelNo();
		if(!telNo.equals(bizOrder.getStuTelNo())) {
			throw new SiteException(SiteCodeEnums.LOGIN_FAILED,"无查看权限");
		}
		returnResult.setData(bizOrder);
		return returnResult;
	}
	
	
}
